package cn.yzw.jc.trace.util;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 超出容量后 淘汰最早的key
 *
 * @author liucan@yzw.cn write on 2024/1/11 13:52
 */
public class LruLinkedHashMap<K, V> extends LinkedHashMap<K, V> {
    private final int capacity;

    public LruLinkedHashMap(int capacity) {
        this.capacity = capacity;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        return size() > capacity;
    }
}
